Skip to content

[FEATURE] add dither, impulsive noise detection, regularized inversion and near/far-field merging - #113

Open
aguirreSL wants to merge 1 commit into
PyTTaMaster:developmentfrom
aguirreSL:dev-measurement_tools
Open

aguirreSL wants to merge 1 commit into
PyTTaMaster:developmentfrom
aguirreSL:dev-measurement_tools

Conversation

@aguirreSL

Copy link
Copy Markdown

Adds to pytta.functions four tools for measurements that the ITA-Toolbox has in its measurement application (ita_dither, ita_impulsiveNoiseDetection, ita_invert_spk_minphase_regularization and ita_add_nearfield_farfield_measurements):

  1. dither(signal, bits=24, kind='tri', quiet=False, seed=None): dither noise added before quantization to bits bits, rectangular, triangular or Gaussian (Lipshitz, Wannamaker and Vanderkooy, "Quantization and dither: a theoretical survey", J. Audio Eng. Soc. 40(5), 1992). With quiet, silent samples stay silent.
  2. impulsive_noise(ir, excitation, noise_start, threshold=20): the part of a measured impulse response after noise_start, convolved again with the excitation, rebuilds the background noise of the recording; L_max_rms = 20 lg(max / rms) of that noise above 20 dB flags an impulsive event. It returns the flag, the level and the noise.
  3. invert_spectrum(signal, freqRange, minimum_phase=False): the regularized inverse conj(H) / (|H|² + ε) (Kirkeby, Rubak, Nelson and Farina, 1999), with ε negligible inside freqRange and half the largest |H|² outside it, crossfaded over half an octave, the rule that ImpulsiveResponse uses for its regularization. With minimum_phase the inverse gets the minimum phase of its magnitude.
  4. merge_near_far(near, far, crossover, order=4, port=None, port_ratio=1): a loudspeaker response from a near-field measurement below the crossover and a far-field one above it (Keele, "Low-frequency loudspeaker assessment by nearfield sound-pressure measurement", J. Audio Eng. Soc. 22(3), 1974). The near-field response, with a port response added for a vented box, is aligned in time and level with the far-field one and crossfaded with power-complementary Butterworth weights that add up to 1.

These ITA functions belong to an application of the ITA-Toolbox whose license is "all rights reserved", so only their help text was read and the functions are written from the references.

The tests in tests/test_measurement_tools.py print the measured values:

  1. With triangular dither the total error of an 8-bit quantizer on a sine of 1.5 steps has the power step²/4 (1.001 of it) and no mean on either half wave (9.1e-4 step), as the theory predicts.
  2. With an excitation of flat magnitude, L_max_rms is 12.8 dB for Gaussian noise alone and 33.2 dB when a click falls in the recording.
  3. The inverse of a band-pass filter is exact inside the range (6.6e-9, and 9.7e-9 with minimum phase), and the minimum phase inverse holds more energy at every instant from its start than the zero phase one with the same magnitude.
  4. A near-field response 20 dB louder and 100 samples earlier than the far-field one is merged back into the far-field one (1.9e-8).

Checked with Python 3.12, numpy 1.26 and scipy 1.17. The 7 failures of development (3 in test_h5io.py, 4 in test_pyttasave.py) are the same with and without this change.

Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com

…_far

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant